package com.amap.api.col.s;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import com.amap.api.col.s.cf;
import com.amap.api.col.s.y;
import com.amap.api.services.core.AMapException;
import com.amap.api.services.interfaces.IWeatherSearch;
import com.amap.api.services.weather.LocalWeatherForecastResult;
import com.amap.api.services.weather.LocalWeatherLiveResult;
import com.amap.api.services.weather.WeatherSearch;
import com.amap.api.services.weather.WeatherSearchQuery;

/* compiled from: WeatherSearchCore.java */
/* loaded from: classes.dex */
public final class bu implements IWeatherSearch {
    private Context a;
    private WeatherSearchQuery b;
    private WeatherSearch.OnWeatherSearchListener c;
    private LocalWeatherLiveResult d;
    private LocalWeatherForecastResult e;
    private Handler f;

    public bu(Context context) throws AMapException {
        this.f = null;
        cg a = cf.a(context, m.a(false));
        if (a.a != cf.c.SuccessCode) {
            throw new AMapException(a.b, 1, a.b, a.a.a());
        }
        this.a = context.getApplicationContext();
        this.f = y.a();
    }

    @Override // com.amap.api.services.interfaces.IWeatherSearch
    public final WeatherSearchQuery getQuery() {
        return this.b;
    }

    @Override // com.amap.api.services.interfaces.IWeatherSearch
    public final void setQuery(WeatherSearchQuery weatherSearchQuery) {
        this.b = weatherSearchQuery;
    }

    @Override // com.amap.api.services.interfaces.IWeatherSearch
    public final void searchWeatherAsyn() {
        try {
            ax.a().a(new Runnable() { // from class: com.amap.api.col.s.bu.1
                {
                    bu.this = this;
                }

                @Override // java.lang.Runnable
                public final void run() {
                    Message obtainMessage = y.a().obtainMessage();
                    obtainMessage.arg1 = 13;
                    Bundle bundle = new Bundle();
                    if (bu.this.b == null) {
                        try {
                            throw new AMapException(AMapException.AMAP_CLIENT_INVALID_PARAMETER);
                        } catch (AMapException e) {
                            n.a(e, "WeatherSearch", "searchWeatherAsyn");
                        }
                    } else if (bu.this.b.getType() == 1) {
                        try {
                            try {
                                bu buVar = bu.this;
                                buVar.d = buVar.a();
                                bundle.putInt("errorCode", 1000);
                            } catch (AMapException e2) {
                                bundle.putInt("errorCode", e2.getErrorCode());
                                n.a(e2, "WeatherSearch", "searchWeatherAsyn");
                            } catch (Throwable th) {
                                n.a(th, "WeatherSearch", "searchWeatherAnsyThrowable");
                            }
                        } finally {
                            y.o oVar = new y.o();
                            obtainMessage.what = 1301;
                            oVar.b = bu.this.c;
                            oVar.a = bu.this.d;
                            obtainMessage.obj = oVar;
                            obtainMessage.setData(bundle);
                            bu.this.f.sendMessage(obtainMessage);
                        }
                    } else if (bu.this.b.getType() == 2) {
                        try {
                            try {
                                bu buVar2 = bu.this;
                                buVar2.e = buVar2.b();
                                bundle.putInt("errorCode", 1000);
                            } catch (AMapException e3) {
                                bundle.putInt("errorCode", e3.getErrorCode());
                                n.a(e3, "WeatherSearch", "searchWeatherAsyn");
                            } catch (Throwable th2) {
                                n.a(th2, "WeatherSearch", "searchWeatherAnsyThrowable");
                            }
                        } finally {
                            y.n nVar = new y.n();
                            obtainMessage.what = 1302;
                            nVar.b = bu.this.c;
                            nVar.a = bu.this.e;
                            obtainMessage.obj = nVar;
                            obtainMessage.setData(bundle);
                            bu.this.f.sendMessage(obtainMessage);
                        }
                    }
                }
            });
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    public LocalWeatherLiveResult a() throws AMapException {
        w.a(this.a);
        WeatherSearchQuery weatherSearchQuery = this.b;
        if (weatherSearchQuery == null) {
            throw new AMapException(AMapException.AMAP_CLIENT_INVALID_PARAMETER);
        }
        bc bcVar = new bc(this.a, weatherSearchQuery);
        return LocalWeatherLiveResult.createPagedResult((WeatherSearchQuery) bcVar.c_(), bcVar.c());
    }

    public LocalWeatherForecastResult b() throws AMapException {
        w.a(this.a);
        WeatherSearchQuery weatherSearchQuery = this.b;
        if (weatherSearchQuery == null) {
            throw new AMapException(AMapException.AMAP_CLIENT_INVALID_PARAMETER);
        }
        bb bbVar = new bb(this.a, weatherSearchQuery);
        return LocalWeatherForecastResult.createPagedResult((WeatherSearchQuery) bbVar.c_(), bbVar.c());
    }

    @Override // com.amap.api.services.interfaces.IWeatherSearch
    public final void setOnWeatherSearchListener(WeatherSearch.OnWeatherSearchListener onWeatherSearchListener) {
        this.c = onWeatherSearchListener;
    }
}
